//
//  CPStatusOriginalView.swift
//  weibo
//
//  Created by zcp on 16/5/16.
//  Copyright © 2016年 zcp. All rights reserved.
//

import UIKit

class CPStatusOriginalView: UIView {

    //模型属性
    var status: CPStatus? {
        
        didSet{
            iconView.sd_setImageWithURL(NSURL(string: (status?.user?.profile_image_url)!))
            nameLable.text = status?.user?.screen_name
            timeLabel.text = status?.created_at
            sourceLabel.text = status?.source
            verifiedView.image = status?.user?.verifiedImage
            memberView.image = status?.user?.mbrankImage
            contentLabel.text = status?.text
            pictureView.pictureUrls = status?.pictureUrls
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //添加子控件,约束
    private func prepareUI(){
    
        //添加子控件
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberView)
        addSubview(verifiedView)
        addSubview(contentLabel)
        addSubview(pictureView)
        //约束
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(self).offset(cellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView)
            make.leading.equalTo(iconView.snp_trailing).offset(cellMargin)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLable)
            make.bottom.equalTo(iconView)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(timeLabel.snp_trailing).offset(cellMargin)
            make.centerY.equalTo(timeLabel)
        }
        memberView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(nameLable)
            make.leading.equalTo(nameLable.snp_trailing).offset(cellMargin)
            make.size.equalTo(CGSize(width: 14, height: 14))
        }
        verifiedView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 14, height: 14))
            make.centerX.equalTo(iconView.snp_trailing)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(12)
            make.leading.equalTo(self).offset(cellMargin)
//            make.trailing.equalTo(self).offset(-cellMargin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(cellMargin)
            make.size.equalTo(CGSize(width: 359, height: 359))
        }
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView).offset(cellMargin)
        }
        
    }

    //MARK: - 懒加载
    ///用户图像
    private lazy var iconView: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "avatar"))
        imageView.layer.cornerRadius = 17.5
        imageView.layer.masksToBounds = true
        return imageView
        }()
    ///用户名称
    private lazy var nameLable: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFontOfSize(NameFontSize)
        label.textColor = UIColor.darkGrayColor()
        return label
        }()
    ///时间
    private lazy var timeLabel:UILabel = {
        let label = UILabel()
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(TimeFontSize)
        return label
        }()
    ///来源
    private lazy var sourceLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.lightGrayColor()
        label.font = UIFont.systemFontOfSize(TimeFontSize)
        return label
        }()
    ///会员等级
    private lazy var memberView:UIImageView = UIImageView(image: UIImage(named: ""))
    ///认证类型
    private lazy var verifiedView: UIImageView = UIImageView(image: UIImage(named: ""))
    
    ///内容
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 0
        label.font = UIFont.systemFontOfSize(CellStatusFontSize)
        label.textColor = UIColor.darkGrayColor()
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * cellMargin
        return label
        }()
    ///微博配图
    private lazy var pictureView:CPPictureView = CPPictureView()
}
